package com.daoyintech.controllers.hongbao;

import com.daoyintech.services.RedEnvelopeService;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by xuzhaolin on 15/12/29.
 */
@RestController
@RequestMapping(value = "/weixin/hongbao/red_envelopes")
public class RedEnvelopeController {

    @Autowired
    private RedEnvelopeService redEnvelopeService;

    @RequestMapping(value="/index",method = RequestMethod.GET)
    public Object index(){
        return redEnvelopeService.findAll();
    }

    @RequestMapping(value="/create",method = RequestMethod.GET)
    public Object create(HttpServletRequest request){
        String money  = request.getParameter("money");
        String count  = request.getParameter("count");
        for(int i =0; i< Integer.parseInt(count);i++){
            redEnvelopeService.create(money);
        }
        return "forward:/index";
    }

    @RequestMapping(value = "/bind")
    public Object bind(HttpServletRequest request){
        String event_id = request.getParameter("event_id");
        String red_envelope_id = request.getParameter("red_envelope_id");
        String number = request.getParameter("number");
        return redEnvelopeService.bindRedEnvelopeAndEvent(Long.valueOf(event_id),Integer.valueOf(number),Long.valueOf(red_envelope_id));
    }

    @RequestMapping(value = "/delete")
    public Object deleteAll(){
        redEnvelopeService.deleteAll();
        return "forward:/index";
    }


}
